<!-- A page that is used to test that a dynamic form fill feature works properly. -->
<body>
  <form name="one" action="https://example.com/" method="post">
    Name: <input type="text" name="firstname" id="firstname_1" autocomplete="given-name"><br>
   <input type="text" name="firstname" id="firstname_2" autocomplete="given-name" style="display: none"><br>
    Address: <input type="text" name="address1" id="address1_3"><br>
    Country: <select name="country" id="country_4" onchange="CountryChanged()">
      <option value="CA">Canada</option>
      <option value="US">United States</option>
    </select>
    <input type="reset" value="Reset">
    <input type="submit" value="Submit" id="profile_submit">
</form>
<br><br>
    <form name="one" action="https://example.com/" method="post">
    Name: <input type="text" name="firstname" id="firstname_5" autocomplete="given-name"><br>
   <input type="text" name="firstname" id="firstname_6" autocomplete="given-name" style="display: none"><br>
    Address: <input type="text" name="address1" id="address1_7"><br>
    Country: <select name="country" id="country_8" onchange="CountryChanged()">
      <option value="CA">Canada</option>
      <option value="US">United States</option>
    </select>
    <input type="reset" value="Reset">
    <input type="submit" value="Submit" id="profile_submit">
  </form>
</body>

<script>


var notify_on_address_input_change = false;
var address_input_changed = false;

function CountryChanged() {
  // Reset the value of the address field.
  var address1 = document.getElementById('address1_7');
  address1.value = '';
  address1.onchange = function() {
    if (notify_on_address_input_change)
      window.domAutomationController.send(address1.value != '');
    else
      address_input_changed = true;
  }

  // Change the element that triggered the autofill. Remove it, and make another
  // field visible. This is to test if the autofill can handle the case where
  // the clicked on element is no longer valid.
  var first_name_input = document.getElementById("firstname_5");
  first_name_input.setAttribute("style", "display: none");

  var name_later = document.getElementById("firstname_6");
  name_later.removeAttribute('style');
}


function hasRefilled() {
  var address1 = document.getElementById('address1_7');
  if (address1 && address_input_changed) {
    window.domAutomationController.send(address1.value != '');
  } else {
    notify_on_address_input_change = true;
  }
}

</script>

